package org.shuma.goods.utils;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

/**
 * @author zhao haitao
 * @date 2024/06/17 11:23 AM
 */
@Setter
@Getter
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Result<T> implements Serializable {

    //  getter和  setter
    private Integer code;
    private String message;
    private T data;
    private String description;

    public Result() { //如果什么参数都不传，则返回 { 200; "操作成功"; }
        this.code = HttpCodeEnum.SUCCESS.getCode();
        this.message = HttpCodeEnum.SUCCESS.getMsg();
        this.description = "";
        this.data = null;
    }

    public Result<T> error(HttpCodeEnum enums, String description) {
        this.code = enums.getCode();
        this.message = enums.getMsg();
        this.description = description;
        this.data = null;
        return this;
    }


    public Result<T> ok(Integer code, T data, String msg) {
        this.code = code;
        this.data = data;
        this.message = msg;
        this.description = "";
        return this;
    }

    public Result<T> ok(T data) {
        this.data = data;
        this.code= HttpCodeEnum.SUCCESS.getCode();
        this.message = HttpCodeEnum.SUCCESS.getMsg();
        this.description = "";
        return this;
    }

    public Result<T> ok() {
        this.code = HttpCodeEnum.SUCCESS.getCode();
        this.message = HttpCodeEnum.SUCCESS.getMsg();
        this.description = "";
        this.data = null;
        return this;
    }

}
